CFLAGS = -I./board/inc/ -I./app/ -I./test/data_proc/ -I./app/wontec/ -I./app/procedure/ -I./app/config/

CFLAGS += -I/home/hcgy/extend_disk/libxml2/libxml2-2.9.10/install_arm/include/libxml2/

CFLAGS += -I/home/hcgy/extend_disk/libjson/jsoncpp/include/

objects = gpio.o main.o Serial.o can_app.o can_uim.o board_data_proc.o rs485.o common.o tecan.o sharemem.o 

objects+= ack_msg.o motor_init.o barcode.o uim_motor_config.o

wontec_objects = wontec_485.o wontec_wt184.o wontec_wtais42.o

procedure_objects = procedure.o config.o json_config.o

LDFLAGS = -lpthread -L. -lwontec -lprocedure -Wl,-rpath=/mnt/nandflash/apps/libs

LDFLAGS+= -L/home/hcgy/extend_disk/libxml2/libxml2-2.9.10/install_arm/lib/ -lxml2
LDFLAGS+= -L/home/hcgy/extend_disk/libjson/jsoncpp/build/debug/src/lib_json/ -ljsoncpp

QPCR=1

_DEBUG_=1

GP_BETA_2=0

main_out=main

install_path_base=/mnt/hgfs/tools/bin/

ifeq ($(GP_BETA_2),1)
CFLAGS+= -D_GP_BETA_2
endif

ifeq ($(QPCR),1)
CFLAGS+= -D_QPCR
main_out=main_qpcr
install_path_1=$(install_path_base)/qpcr/
else
install_path_1=$(install_path_base)/purify/
endif

MAKE_GP1=0

#ifeq ($(MAKE_GP1),1)
#CFLAGS+= -D_GP_1
#install_path2=$(install_path_1)/gp1/
#else
#install_path2=$(install_path_1)/gp2/
#endif


ifeq ($(GP_BETA_2),1)
install_path=$(install_path_1)/beta2/
else
install_path=$(install_path_1)/beta1/
endif



ifeq ($(_DEBUG_),1)
CFLAGS+= -g
endif

all:$(objects) wontec procedure
	$(CXX) -o $(main_out) $(objects) $(LDFLAGS)
install_uim:
	mv main main_uim
	cp -f main_uim /mnt/hgfs/tools/bin/

install_lec:
	mv main main_lec
	cp -f main_lec /mnt/hgfs/tools/bin/

install_all:
	cp -f $(main_out) /mnt/hgfs/tools/bin/
	cp -f libwontec.so /mnt/hgfs/tools/bin/
	cp -f libprocedure.so /mnt/hgfs/tools/bin/

install_qpcr:
	cp -f $(main_out) /mnt/hgfs/tools/bin/
	cp -f libwontec.so /mnt/hgfs/tools/bin/
	cp -f libprocedure.so /mnt/hgfs/tools/bin/

install:
	cp -f $(main_out) $(install_path)
	cp -f libwontec.so $(install_path)
	cp -f libprocedure.so $(install_path)

gpio.o:./board/src/gpio.cpp
	$(CXX) -c -o gpio.o ./board/src/gpio.cpp $(CFLAGS)

Serial.o:./board/src/Serial.cpp
	$(CXX) -c -o Serial.o ./board/src/Serial.cpp $(CFLAGS)

rs485.o:./board/src/rs485.cpp ./board/inc/rs485.h
	$(CXX) -c -o $@ ./board/src/rs485.cpp $(CFLAGS)

can_app.o:./board/src/can_app.cpp ./app/common.h
	$(CXX) -c -o can_app.o ./board/src/can_app.cpp $(CFLAGS)

main.o:./app/main.cpp ./app/common.h
	$(CXX) -c  -o main.o ./app/main.cpp $(CFLAGS)

can_uim.o: ./app/can_uim.cpp ./app/common.h
	$(CXX) -c -o can_uim.o ./app/can_uim.cpp $(CFLAGS)

board_data_proc.o: ./test/data_proc/board_data_proc.cpp ./test/data_proc/board_data_proc.h
	$(CXX) -c -o board_data_proc.o ./test/data_proc/board_data_proc.cpp $(CFLAGS)

rs485_test.o:./app/rs485_test.cpp ./board/inc/rs485.h
	$(CXX) -c  -o $@ $< $(CFLAGS)

rs485_test:rs485.o Serial.o gpio.o rs485_test.o
	$(CXX) -o $@ $^ -lpthread
	cp -f rs485_test /mnt/hgfs/tools/bin/
wontec:$(wontec_objects)
	$(CXX) -shared -o libwontec.so $^

wontec_485.o:./app/wontec/wontec_485.cpp ./app/wontec/wontec_485.h
	$(CXX) -c -o $@ $< -fPIC $(CFLAGS)

wontec_wt184.o:./app/wontec/wontec_wt184.cpp ./app/wontec/wontec_wt184.h 
	$(CXX) -c -o $@ $< -fPIC $(CFLAGS)

wontec_wtais42.o:./app/wontec/wontec_wtais42.cpp ./app/wontec/wontec_wtais42.h 
	$(CXX) -c -o $@ $< -fPIC $(CFLAGS)

common.o:./app/common.cpp ./app/common.h
	$(CXX) -c -o $@ $< $(CFLAGS)

procedure.o:./app/procedure/procedure.cpp ./app/procedure/procedure.h
	$(CXX) -c -o $@ $< -fPIC $(CFLAGS)

config.o:./app/config/config.cpp ./app/config/config.h
	$(CXX) -c -o $@ $< -fPIC $(CFLAGS)

ack_msg.o:./app/ack_msg.cpp ./app/ack_msg.h
	$(CXX) -c -o $@ $< -fPIC $(CFLAGS) 

motor_init.o: ./app/motor_init.cpp ./app/motor_init.h
	$(CXX) -c -o $@ $< -fPIC $(CFLAGS) 

uim_motor_config.o:./app/uim_motor_config.cpp ./app/uim_motor_config.h
	$(CXX) -c -o $@ $< -fPIC $(CFLAGS) 

json_config.o:./app/config/json_config.cpp ./app/config/config.h
	$(CXX) -c -o $@ $< -fPIC $(CFLAGS)

tecan.o:./app/tecan.cpp ./app/tecan.h
	$(CXX) -c -o $@ $< -fPIC $(CFLAGS)

sharemem.o:./app/sharemem.cpp ./app/sharemem.h
	$(CXX) -c -o $@ $< -fPIC $(CFLAGS)

procedure:$(procedure_objects)
	$(CXX) -shared -o libprocedure.so $^

barcode.o:./test/barcode/barcode.cpp ./test/barcode/barcode.h
	$(CXX) -c -o $@ $< -fPIC $(CFLAGS)

.PHONY : clean
clean:
	rm $(main_out) *.o *.so
